<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Services\Upload\UploadService;
use Auth;
use Illuminate\Http\Request;
use Storage;

class UploadController extends Controller
{
    //    暂停使用

    public function __construct()
    {
        return $this->middleware(['auth:sanctum']);
    }

    //后台图片上传
    public function upload(Request $request)
    {

        $request->validate(['file' => ['required', 'mimes:xls,xlsx,docx,jpg,jpeg,png,mp3,mp4,mov,application/pdf,
        application/msword,application/octet-stream,application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,audio/mp4,video/quicktime', 'max:20000']]);
        return UploadService::local($request->file);
    }


    //指定文件上传(小程序)

    public function uploadFiles(Request $request)
    {
        $request->validate(['file' => ['required', 'mimes:xls,xlsx,docx,jpg,jpeg,png,mp3,mp4,mov,application/pdf,
        application/msword,application/octet-stream,application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,audio/mp4,video/quicktime', 'max:20000']]);
        return UploadService::local($request->file);
    }

//    wangeditor上传接口

    public function wangeditor(Request $request)
    {
        $request->validate(['wangeditor-uploaded-image' => [
            'required', 'mimes:png,jpg,jpeg,svg', 'max:2000'
        ]]);
        return UploadService::wangEditer($request['wangeditor-uploaded-image']);
    }

    //小程序上传控制器方法
    public function wxUpload(Request $request)
    {

        $request->validate(['img' => [
            'required', 'mimes:png,jpg,jpeg,svg', 'max:2000'
        ]]);
        return UploadService::wxUpload($request->img);
    }
}
